package heuristicas;

import java.awt.Point;
import java.util.ArrayList;

import api.Interface;

public class Heuristicas {
	//http://alanchavez.com/pathfinding-con-obstaculos-en-as3-a-con-heuristica-euclidiana-manhattan-diagonal

	public static int Manhattan (Point p) {
		int dx = p.x - Interface.getTablero().getRobot().getPosFinal().x;
		int dy = p.y - Interface.getTablero().getRobot().getPosFinal().y;	
	
		return Math.abs(dx)+ Math.abs(dy);
	}

	
	public static int Manhattan (ArrayList<Point> lis) {        
        int tam = lis.size();
        
        int x = lis.get(tam-1).x;
        int y = lis.get(tam-1).y;
        int X = Interface.getTablero().getRobot().getPosFinal().x;
        int Y = Interface.getTablero().getRobot().getPosFinal().y;              

        return Math.abs(X-x) + Math.abs(Y-y) + tam;
	}

	
	public static int Euclidiana (Point p) {		
		int dx = p.x - Interface.getTablero().getRobot().getPosFinal().x;
		int dy = p.y - Interface.getTablero().getRobot().getPosFinal().y;
		
		return (int) (Math.sqrt(dx * dx + dy * dy));
	}
	

	public static int Euclidiana (ArrayList<Point> lis) {
        int tam = lis.size();
        
        int x = lis.get(tam-1).x;
        int y = lis.get(tam-1).y;
        int X = Interface.getTablero().getRobot().getPosFinal().x;
        int Y = Interface.getTablero().getRobot().getPosFinal().y;
        
        int dx = x - X;
        int dy = y - Y;
        
        return (int) (Math.sqrt(dx * dx + dy * dy)) + tam;
	}

	
	public static int Diagonal (Point p) {
		int x = p.x;
		int y = p.y;
		int X = Interface.getTablero().getRobot().getPosFinal().x;
		int Y = Interface.getTablero().getRobot().getPosFinal().y;
		
		int dx = Math.abs(X-x);
		int dy = Math.abs(Y-y);
		
		int diagonal = Math.min(dx, dy);
		int derecho = dx + dy;
		
		double costoDiagonal = Math.sqrt(2);
		// costo lateral lo omitimos porque vale 1, un paso
		
		return ((int) costoDiagonal *  diagonal + derecho - 2 * diagonal);
	}

	
	public static int Diagonal (ArrayList<Point> lis) {
        int tam = lis.size();
        
        int x = lis.get(tam-1).x;
        int y = lis.get(tam-1).y;
        int X = Interface.getTablero().getRobot().getPosFinal().x;
        int Y = Interface.getTablero().getRobot().getPosFinal().y;
        
        int dx = Math.abs(X-x);
        int dy = Math.abs(Y-y);
        
        int diagonal = Math.min(dx, dy);
        int derecho = dx + dy;
        
        double costoDiagonal = Math.sqrt(2);
        // costo lateral lo omitimos porque vale 1, un paso
        
        return ((int) costoDiagonal *  diagonal + derecho - 2 * diagonal) + tam;
	}
	
	
	public static int Mahalanobis (Point p) {
		int x = p.x;
		int y = p.y;
		int X = Interface.getTablero().getRobot().getPosFinal().x;
		int Y = Interface.getTablero().getRobot().getPosFinal().y;
		
		int dx = Math.abs(X-x);
		int dy = Math.abs(Y-y);
		
		return Math.max(dx, dy);
	}
	
	public static int Mahalanobis (ArrayList<Point> lis) {
        int tam = lis.size();
        
        int x = lis.get(tam-1).x;
        int y = lis.get(tam-1).y;
        int X = Interface.getTablero().getRobot().getPosFinal().x;
        int Y = Interface.getTablero().getRobot().getPosFinal().y;
        
        int dx = Math.abs(X-x);
        int dy = Math.abs(Y-y);
        
        return Math.max(dx, dy) + tam;
	}
}
